package cn.nexttec.noteplayer.databases.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import cn.nexttec.noteplayer.models.PlayRecord

@Dao
interface PlayRecordDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(record: PlayRecord): Long

    @Update
    fun updateRecord(record: PlayRecord)

    @Query("SELECT * FROM PlayRecord ORDER BY LastPlayTime DESC LIMIT 1")
    fun getLastPlay():PlayRecord

    @Query("SELECT * FROM PlayRecord ORDER BY LastPlayTime DESC LIMIT :pageCount OFFSET (:page - 1) * :pageCount")
    fun getPlayHistory(page:Int, pageCount:Int):List<PlayRecord>

    @Query("SELECT * FROM PlayRecord WHERE VideoMd5 = :videoMd5")
    abstract fun getRecord(videoMd5: String): PlayRecord?
}